﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Tank
{
    /// <summary>
    /// 初始化
    /// </summary>
    public class Init
    {
        /// <summary>
        /// 启动
        /// </summary>
        public static void Start()
        {
            string map = ReadFile(AppDomain.CurrentDomain.BaseDirectory + "Grade.map");
            Data.MapDatas = JsonConvert.DeserializeObject<List<MapData>>(map);
        }

        /// <summary>
        /// 读取文件
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private static string ReadFile(string path)
        {
            if (!File.Exists(path))
                throw new Exception($"【{path}】文件不存在");
            using (StreamReader sr = new StreamReader(path, Encoding.UTF8))
            {
                return sr.ReadToEnd();
            }
        }

    }
}
